<template>
  <PageWrapper contentBackground contentClass="flex" dense contentFullHeight fixedHeight>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleAdd">新增网站</a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                label: '编辑',
                icon: 'ant-design:edit-outlined',
                onClick: handleEdit.bind(null, record),
                // auth: 'other', // 根据权限控制是否显示: 无权限，不显示
              },
              {
                label: '删除',
                icon: 'ic:outline-delete-outline',
                onClick: handleDelete.bind(null, record),
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
    <EditCareSiteModal @register="registerModal" @success="handleSuccess" />
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { getCareSiteColumns, searchFormSchema } from '../tableData';
  import { PageWrapper } from '@/components/Page';
  import { useModal } from '@/components/Modal';
  import EditCareSiteModal from './EditCareSiteModal.vue';

  import { getCareSiteListApi } from '@/api/hopefly/api';

  const [registerModal, { openModal }] = useModal();
  const [registerTable, { reload }] = useTable({
    title: '',
    api: (params) => {
      return getCareSiteListApi(params);
    },
    columns: getCareSiteColumns(),
    pagination: { pageSize: 10 },
    showIndexColumn: false,
    useSearchForm: true,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    actionColumn: {
      width: 160,
      title: '操作',
      dataIndex: 'action',
    },
  });
  function handleAdd() {
    openModal(true, { isUpdate: false });
  }
  function handleEdit(record: any) {
    console.log('handleEdit', record);
    openModal(true, { record, isUpdate: true });
  }
  function handleDelete(record: any) {
    console.log('handleEdit', record);
  }
  function handleSuccess() {
    reload();
  }
</script>
